from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches",["enable-automation"])
op.add_experimental_option("useAutomationExtension",False)
driver = webdriver.Chrome(options = op)

driver.get(r"http://news.baidu.com/")

#找到第一条热点新闻链接
firstnewele= driver.find_element(By.XPATH,"//*[@id='pane-news']/div/ul/li[1]/strong/a")
content = firstnewele.text
firstnewele.click()
sleep(3)

current = driver.current_window_handle
all_handle = driver.window_handles
print("current", current)
print("------------------")
print(all_handle)

driver.switch_to.window(all_handle[1])
print(driver.title)
print("current", driver.current_window_handle)

assert content in driver.title

driver.quit()

